package data;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class DaoSession {
	private SqlSession sqlSession;

	DaoSession(SqlSessionFactory factory) {
		this.sqlSession = factory.openSession(false);
	}

	/*protected void finalize() throws Throwable {
		close();
	}*/
	public void commit(){
		sqlSession.commit();
	}	
	
	public void rollback(){
		sqlSession.rollback();
	}
	
	public void close(){
		if (sqlSession != null){
			sqlSession.close();
		}
	}
	
	public int insert(String statement, Object parameter){
		return sqlSession.insert(statement, parameter);
	}

	public int update(String statement, Object parameter){
		return sqlSession.update(statement, parameter);
	}
	
	public int delete(String statement, Object parameter){
		return sqlSession.delete(statement, parameter);
	}
	
	public Object selectOne(String statement){
		return sqlSession.selectOne(statement);
	}

	public Object selectOne(String statement, Object parameter){
		return sqlSession.selectOne(statement, parameter);
	}
	
	@SuppressWarnings("unchecked")
	public List selectList(String statement, Object parameter){
		return sqlSession.selectList(statement, parameter);
	}

	@SuppressWarnings("unchecked")
	public List selectList(String statement){
		return sqlSession.selectList(statement);
	}
	@SuppressWarnings("unchecked")
	public List selectList(String statement, Object parameter, int startNo, int count){
		return sqlSession.selectList(statement, parameter, new RowBounds(startNo, count));
	}
}
